<!DOCTYPE html>
<HTML>

<HEAD>
	<title>菜单选择</title>
	<meta charset="utf-8">
	<script type="text/javascript" charset="UTF-8" src="../../../../static/js/header_base.js"></script>
	<script type="text/javascript" charset="UTF-8" src="../../../../static/js/header_ztree.js"></script>
	<script type="text/javascript" charset="UTF-8" src="../../../../static/js/header_com.js"></script>
	<script type="text/javascript">
		var layer;
		var ztreeObj;
		layui.config({
			base: "../../../../static/js/"
		}).extend({
			"application": "application",
			"publicUtil": "publicUtil"
		})
		layui.use(['layer', 'application', "publicUtil", 'application','jquery'], function () {
			layer = parent.layer,
			application = layui.application,
			publicUtil = layui.publicUtil,
			_$ = layui.jquery;
			//ztree设置
			var setting = {
				view: {
					selectedMulti: false
				},

				data: {
					simpleData: {
						enable: true,
						idKey: "id",
						pIdKey: "parentId"
						// rootPId: 0									
					}
				},
				check: {
					enable: true,
					chkStyle: "radio", //单选框
					radioType: "all" //对所有节点设置单选
				}
			};

			_$(document).ready(function () {
				//重置按钮
				//生产环境具体考虑
				_$("#reset").click(function () {
					ztreeObj.checkAllNodes(true);
				});


				_$.ajax({
					url: application.SERVE_URL + '/sys/sysmenu/list',
					success: function (data) {
						ztreeObj = $.fn.zTree.init($("#treeDemo"), setting, data.data); //加载数据
						//获取根节点个数,getNodes获取的是根节点的集合
						var nodeList = ztreeObj.getNodes();　　　　　　 //展开第一个根节点
						ztreeObj.expandNode(nodeList[0], true);
						//树回显
						publicUtil.setTreeSel(_$(".parentId", parent.document).val(), ztreeObj);

					}
				});

				_$("#getSelectData").click(function () {
					publicUtil.setAcrossName(ztreeObj.getCheckedNodes(), ".parentId", ".parentName")
				})
			});

		});
	</script>
</HEAD>

<BODY class="childrenBody">
	<div>
		<ul id="treeDemo" class="ztree"></ul>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12" style="float: right; bottom: 10px; position:fixed;">
		<div class="layui-input-block" style="margin-bottom: 10px;">
			<a class="layui-btn layui-btn-sm" lay-submit="" lay-filter="getSelectData" id="getSelectData">确认</a>
			<a class="layui-btn layui-btn-sm layui-btn-primary" id="reset">重置</a>
		</div>
	</div>
</BODY>

</HTML>
